package lu.uni.adtool.adtconverter;

import lu.uni.adtool.adtree.ADTNode;
import lu.uni.adtool.adtree.ADTreeNode;
import lu.uni.adtool.adtree.Node;

/**
 * A tree node for RTED algorithm.
 * 
 * @author Piot Kordy
 */
public class LblTree extends ADTNode
{
  /**
   * Hook to store temporary data.
   */
  private Object tmpData;

  /**
   * Associated atack defense tree node.
   */
  //private ADTreeNode treeNode;

  /**
   * Constructs a new instance.
   * @param id an id of a tree node.
   */
  public LblTree(final int id)
  {
    super(id);
    tmpData = null;
    //treeNode = null;
  }

  /**
   * Method to set up a temporary hook.
   * @param newTmpData Hook for any data that a method must attach to a tree.
   * Methods can assume, that this data is null and should return it
   * to be null!
   */
  public final void setTmpData(final Object newTmpData)
  {
    this.tmpData = newTmpData;
  }
  /**
   * Gets the treeNode for this instance.
   *
   * @return The treeNode.
   */
  //public final ADTreeNode getTreeNode()
  //{
    //return this.treeNode;
  //}

  /**
   * Sets the treeNode for this instance.
   *
   * @param treeNode The treeNode.
   */
  //public final void setTreeNode(final ADTreeNode treeNode)
  //{
    //this.treeNode = treeNode;
  //}

  /**
   * Returns a temporarily stored data.
   * 
   * @return temporary data object.
   */
  public final Object getTmpData()
  {
    return tmpData;
  }
  /**
   * Return label for comparison for minimal edit tree distance.
   * 
   * @return label for the node
   */
  public final String getLabel()
  {
    switch (getType()){
      case LEAFO:
      case LEAFP:
        return getName();
      case OO:
        return "oo()";
      case OP:
        return "op()";
      case AP:
        return "ap()";
      case AO:
        return "op()";
      case CP:
        return "cp()";
      case CO:
        return "co()";
      default:
        return "null";
    }
  }
  /**
   * Calculates number of nodes.
   * 
   * @return number of nodes in the subtree.
   */
  public final int getNodeCount()
  {
    int sum = 1;
    if (children != null){
      for(Node n:children){
        sum += ((LblTree)n).getNodeCount();
      }
    }
    return sum;
  }
  public String toString(int test){
    LabelDictionary ld = new LabelDictionary();
    return super.toString(new InfoTree(this, ld));

  }
}

